package com.coderman.infosys.auth.app.facadeimpl.role;

import com.coderman.infosys.auth.api.dto.role.request.CreateRoleGroupRequestDTO;
import com.coderman.infosys.auth.api.dto.role.request.CreateRoleRequestDTO;
import com.coderman.infosys.auth.api.dto.role.request.UpdateRoleGroupRequestDTO;
import com.coderman.infosys.auth.api.dto.role.request.UpdateRoleRequestDTO;
import com.coderman.infosys.auth.api.facade.role.RoleFacade;
import com.coderman.infosys.auth.api.facade.role.RoleGroupFacade;
import com.coderman.infosys.auth.app.convert.RoleConvert;
import com.coderman.infosys.auth.app.convert.RoleGroupConvert;
import com.coderman.infosys.auth.domain.bo.role.RoleBO;
import com.coderman.infosys.auth.domain.bo.role.RoleGroupBO;
import com.coderman.infosys.auth.domain.enums.errors.RoleErrorEnum;
import com.coderman.infosys.auth.domain.enums.errors.RoleGroupErrorEnum;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * @Description:角色组接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class RoleGroupFacadeImpl implements RoleGroupFacade{

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserRoleRepository userRoleRepository;

    @Override
    public ResultDataDto<Boolean> createRoleGroup(CreateRoleGroupRequestDTO createRoleGroupRequestDTO){
        RoleGroupBO roleGroupBO = RoleGroupConvert.INSTANCE.dto2bo(createRoleGroupRequestDTO);
        userRoleRepository.saveRoleGroup(roleGroupBO);
        return ResultDataDto.success(true);
    }

    @Override
    public ResultDataDto<Boolean> updateRoleGroup(UpdateRoleGroupRequestDTO updateRoleGroupRequestDTO){
        RoleGroupBO roleGroupBO = RoleGroupConvert.INSTANCE.dto2bo(updateRoleGroupRequestDTO);
        int updateCount = userRoleRepository.updateRoleGroup(roleGroupBO);
        if(updateCount > 0){
            return ResultDataDto.success(true);
        }
        return ResultDataDto.fail(RoleGroupErrorEnum.ROLE_GROUP_UPDATE_ERROR);
    }

    @Override
    public ResultDataDto<Boolean> disableRoleGroup(String roleGroupCode) {
        Boolean b = userRoleRepository.disableRoleGroup(roleGroupCode);
        if(b){
            return ResultDataDto.success(true);
        }
        return ResultDataDto.fail(RoleGroupErrorEnum.ROLE_GROUP_DISABLE_ERROR);
    }

    @Override
    public ResultDataDto<Boolean> enableRoleGroup(String roleGroupCode) {
        Boolean b = userRoleRepository.enableRoleGroup(roleGroupCode);
        if(b){
            return ResultDataDto.success(true);
        }
        return ResultDataDto.fail(RoleGroupErrorEnum.ROLE_GROUP_ENABLE_ERROR);
    }

}